$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'orth/feedbackManage/list',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id_', index: "id_", width: 35, key: true,hidden:true},
            { label: '用户姓名', name: 'name', width: 75,sortable:false},
            { label: '手机号', name: 'phone', width: 95,sortable:false},
            { label: '反馈内容', name: 'content', width: 85,sortable:false},
            { label: '提交日期', name: 'createTime', width: 80,sortable:false}
        ],
        viewrecords: true,

        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    $('.form-horizontal').validationEngine('attach',{
        autoHidePrompt: true,
        autoHideDelay: 2000,
        maxErrorsPerField: 1
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            title: null
        },
        showList: true,
        title:null,
        feedback:{
            status:0
        },
        pictures:[]
    },
    methods: {
        query: function () {
            jQuery("#jqGrid").jqGrid('setGridParam',{page:1});
            vm.reload();
        },
        del: function () {
            var userIds = getSelectedRows();
            if(userIds == null){
                return ;
            }

            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "orth/feedbackManage/delete",
                    contentType: "application/json",
                    data: JSON.stringify(userIds),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getUser: function(){

            var userId = getSelectedRow();
            if(userId == null){
                return ;
            }
            vm.pictures=[];
            vm.showList = false;
            vm.title = "查看";
            $.get(baseURL + "orth/feedbackManage/info/"+userId, function(r){
                vm.feedback = r.feedback;
                if(r.feedback.picUrls!=undefined && r.feedback.picUrls!="")
                  vm.pictures=r.feedback.picUrls.split(",");
            });
        },
        reload: function () {
            vm.showList = true;
            $(".formError").hide();
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'content': vm.q.title},
                page:page
            }).trigger("reloadGrid");
        },
        validator: function () {

        }
    }
});